package com.beike.service.serviceImpl;

import com.beike.entity.LessonDesign;
import com.beike.mapper.LessonDesignMapper;
import com.beike.service.AIService;
import com.beike.service.LessonDesignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LessonDesignServiceImpl implements LessonDesignService {

    @Autowired
    private LessonDesignMapper lessonDesignMapper;

    @Autowired
    private AIService aiService;

    @Override
    public LessonDesign generateDesign(String name, String subject, String grade, int duration) {
        // 调用AI服务生成教学设计
        LessonDesign design = aiService.generateLessonDesign(name, subject, grade, duration);
        lessonDesignMapper.insert(design);
        return design;
    }

    @Override
    public LessonDesign getDesignById(Long id) {
        return lessonDesignMapper.selectById(id);
    }

    @Override
    public LessonDesign saveDesign(LessonDesign design) {
        if (design.getId() == null) {
            lessonDesignMapper.insert(design);
        } else {
            lessonDesignMapper.update(design);
        }
        return design;
    }

    @Override
    public List<LessonDesign> getAllDesigns() {
        return lessonDesignMapper.selectAll();
    }
}